package com.sxj.corejava.code06_lambda表达式;

import java.util.Arrays;
import java.util.List;
import java.util.function.Supplier;

/**
 * @author 石小俊
 * @date 2023年12月2023/12/23日 8:34
 */
public class Test03_供给型接口 {
    public static void main(String[] args) {
        List<String> list = testSupplier(new Supplier<List<String>>() {
            @Override
            public List<String> get() {
                return Arrays.asList("南京","苏州","无锡","常州","泰州","盐城","徐州","连云港","扬州","宿迁","南通","淮安","镇江");
            }
        });
        System.out.println(list);

        List<String> list2 = testSupplier(() -> Arrays.asList("南京","苏州","无锡","常州","泰州","盐城","徐州","连云港","扬州","宿迁","南通","淮安","镇江"));
        System.out.println(list2);
    }

    /**
     * 供给型接口,方法: T get()
     * 接口方法无参有返回值,其泛型类型与方法返回值类型一致
     * @param supplier
     * @return
     */
    public static List<String> testSupplier(Supplier<List<String>> supplier){
        return supplier.get();
    }
}
